package Day05;

import java.util.Arrays;
import java.util.Random;
import java.util.Random;

public class Homework {
    public static void main(String[] args) {
        /*
        //MultiTable九九乘法表 要求：输出九九乘法表
        for (int num = 1; num <= 9; num++) {
            for (int i = 1; i <= num; i++) {
                System.out.print(i + "*" + num + "=" + i * num + "\t");
            }
            System.out.println();
        }

        //数组小代码练习：声明 定义至少两个数组，设计包含一些元素
        int[] arr = new int[10];
        int[] arrrrr = new int[11];
        //数组小代码练习：初始化 定义至少三个数组，演示三种元素初始化方式
        int[] arrr = new int[15];
        int[] arrrr = {1, 2, 3, 4, 5, 6, 7};
        int[] arrrrrr = new int[]{1, 2, 3, 4, 5, 6};

        // 数组小代码练习：访问 定义数组，输出数组的长度 定义数组并分别给每个元素赋值，输出最后一个元素的值 编写代码演示数组操作常见的异常----数组下标越界
        int[] arrrrrrr = new int[4];
        System.out.println(arrrrrrr.length);
        arrrrrrr[0] = 10;
        arrrrrrr[1] = 20;
        arrrrrrr[2] = 30;
        arrrrrrr[3] = 40;
        System.out.println(arrrrrrr[arrrrrrr.length - 1]);


        //数组小代码练习：遍历 定义数组，包含10个元素，遍历数组，给每个元素赋值为0到99之间的随机数，输出每个元素 的值
        Random random = new Random();
        int[] a = new int[10];
        for (int i = 1; i < a.length; i++) {
            a[i] = random.nextInt(100);
            System.out.println(a[i]);
*/
        //复制+扩容
        int[] b = {10, 20, 30, 40, 50};
        b = Arrays.copyOf(b, b.length + 1);
        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i]);
        }

        int[] a = {10, 20, 30, 40, 50, 60};
        int[] c = new int[6];
        System.arraycopy(a, 2, b, 3, 1);

        //定义数组，包含10个元素，遍历数组，给每个元素赋值为0到99之间的随机数并输出，找到数 组元素的最大值并输出，并将最大值放在最后一个元素的下一个位
        int[] d = new int[10];
        for (int e = 0; e < d.length; e++) {
            d[e] = (int) (Math.random() * 100);
            System.out.println(d[e]);
        }
        int max = d[0];
        for (int e = 0; e < d.length; e++) {
            if (d[e] > max) {
                max = d[e];
            }
        }
        System.out.println("最大值为：" + max);


        d = Arrays.copyOf(d,d.length+1);
        d[d.length-1] = max;
        for (int g = 0;g<d.length;g++){
            System.out.println(d[g]);
        }
        // 对数组进行升序排列，并输出排序后的结果
        Arrays.sort(d);
        System.out.println("排序后：");
        for ( int i = 0;i<d.length;i++){
            System.out.println(d[i]);
        }
















































    }


}

